function commonSVM=DetermineCommon(analytes,reducedData,runParams, SVMParams)

oneSVM=cell([1 length(analytes)]);
peakTables=cell([1 length(analytes)]);
for K=1:length(analytes)
    idx =find( reducedData(:,1)==analytes(K) );
    %reduce the number of points to a managable amount
    idx = idx( randperm(length(idx), min([ length(idx) 300])));
    tSingleGroup= reducedData(idx,4:end);
    
    oneSVM{K}=CreateOneClass(tSingleGroup,CopyKernalParameters(SVMParams)) ;
    predictedGroups = svmoneclassval(tSingleGroup,oneSVM{K}.xsup,oneSVM{K}.alpha,oneSVM{K}.rho,oneSVM{K}.kernel,oneSVM{K}.kerneloption);
    t=sort(predictedGroups);
    oneSVM{K}.threshold = t(round(end*.4));
end


%idx = randperm(size(reducedData,1), min([ size(reducedData,1) 100])


% randomize the data so that the stop when full does not bias the data
idx =  randperm( size(reducedData,1),min([1000 size(reducedData,1)]) ) ;

tSingleGroup= reducedData(idx,4:end);
votes =zeros([length(idx) 1]);

figure(6);
for K=1:length(oneSVM)
    tvotes =zeros([length(idx) 1]);
    for I=1:500:size(tSingleGroup,1)
        top = min([ size(tSingleGroup,1) I+500]);
        temp= tSingleGroup(I:top,:);
        predictedGroups = svmoneclassval(temp,oneSVM{K}.xsup,oneSVM{K}.alpha,oneSVM{K}.rho,oneSVM{K}.kernel,oneSVM{K}.kerneloption);
        predictedGroups= predictedGroups>oneSVM{K}.threshold;
        tvotes(I:top)=tvotes(I:top)+predictedGroups;
    end
%     [t, idx]=sort(tvotes);
%     crsIdx= round(length(idx)*.85);
%     offset = t(crsIdx-1)-t(crsIdx)/2;
%    % tv=tvotes;
%     tvotes( idx(crsIdx:end))=tvotes( idx( round(end*.85):end))./2+offset;
%    % tv2 = tv(idx);
     votes=votes + tvotes;
    
    if K==1
        [t, idx]=sort(votes);
        tSingleGroup=tSingleGroup(idx,:);
        votes = votes(idx);
    else
        t =votes;
    end
    [t, idx]=sort(votes);
    plot(t/K);
    hold all
    drawnow;
end
hold off;

commonPeaks = tSingleGroup(votes>= length(oneSVM)-1 ,: );
% % t=t(10:end)/length(oneSVM);
% % d= abs( 100*diff(smooth(t,1000)) -.003 );
% % threshold =mean( t(   d<.0001   ) );
% threshold=mean(t(round( end*.8):end))/length(oneSVM);

commonSVM=CreateOneClass(commonPeaks,SVMParams);

predictedGroups = svmoneclassval(commonPeaks,commonSVM.xsup,commonSVM.alpha,commonSVM.rho,commonSVM.kernel,commonSVM.kerneloption);
[t idx]=sort(predictedGroups,'descend');

commonSVM.threshold =t(round(end*.4));

end